home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / PRINTING.SWG / 0026_PRINTER Handler.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  5KB  |  173 lines

  1. {
  2. RANDALL WOODMAN
  3.  
  4. NOTE: There is a call to a Procedure called YNWin.  It is defined as:
  5.      YNWin(s : String; Var ch : Char; Color : ColorSet);
  6. Color set comes from the ObjectProfessional package from TurboPower software.
  7. YNWin is derived from one of their Objects.  Basically it pops up a Window,
  8. displays the String, s, in the colors specified, and waits For a Y or N Char
  9. from the user.  It returns that result in CH.
  10.      I did not include YNWin in this post.  However, you can easily Write
  11. a Procedure to take it's place.  I only left the calls in place to show you
  12. what I do when I do need interaction from the user.
  13.      The Printer codes used are specific to an Epson compatible Printer.
  14. Check your user manual For other Printer support.
  15. }
  16.  
  17. Unit IThinkClintonsDefecetReductionPackageSucks;
  18.  
  19. Uses
  20.   Dos;
  21.  
  22. Const
  23.   TimedOut   = $01;  { Used to determine the Type of Printer error }
  24.   IOError    = $08;
  25.   OutOfPaper = $20;
  26.   NotBusy    = $80;
  27.   TestAll    = TimedOut+IOError+OutOfPaper;
  28.  
  29. Var
  30.   PrnStatus : Byte;
  31.  
  32. Function PrinterReady : Boolean;
  33. { checks the status of the Printer and returns True if ready      }
  34. { to recieve a Character                                          }
  35. { This Function will return the status of your Printer.  Status   }
  36. { should be interpreted as follows:  (x'90' (d'144') is "Ready"): }
  37. { $01 = Printer Time-out          $02 = Not Used                  }
  38. { $04 = Not Used                  $08 = I/O Error                 }
  39. { $10 = Printer Selected          $20 = Out Of Paper              }
  40. { $40 = Acknowledge               $80 = Not Busy                  }
  41.  
  42. Var
  43.    Regs : Registers;
  44.    TempStatus : Byte;
  45. begin
  46.   With Regs Do
  47.   begin
  48.     DX := 0;
  49.     AX := $0200;
  50.     Intr($17,Regs);
  51.     PrnStatus := Hi(AX);
  52.     TempStatus := PrnStatus;
  53.     PrinterReady := (TempStatus and TestAll = $00);
  54.   end;
  55. end;
  56.  
  57. Procedure GetPrnError(Var ESC : Boolean);
  58. { gets the error that occured With the Printer and gives the user a chance to }
  59. { correct the problem and continue. }
  60. Var
  61.   CH : Char;
  62. begin
  63.   Repeat
  64.     PrnStatus := PrnStatus and TestAll;
  65.     Case PRnStatus OF
  66.       TimedOut   : YNWin('Printer timed out.  Retry??? (Y/N)',Ch,Mycolor);
  67.       IOError    : YNWin('An IOError has occured.  Retry??? (Y/N)',CH,Mycolor);
  68.       OutOfPaper : YNWin('Printer out of paper.  Retry??? (Y/N)',CH,Mycolor);
  69.     else
  70.       YNWin('A Print Device Error has occured.  Retry??? (Y/N)',CH,Mycolor);
  71.     end; { Case }
  72.     if CH = 'N' then
  73.       esc := True;
  74.   Until ESC or PrinterReady;
  75. end;
  76.  
  77. Function EscapePushed : Boolean;
  78. { Checks the keyboard buffer For a Character and test to see if it was the }
  79. { Esc key.  if it was it returns True else it returns False.               }
  80. Var
  81.   CH : Char;
  82. begin
  83.   if KeyPressed then        { Check the keyboard buffer For a Character }
  84.   begin
  85.     CH := ReadKey;          { if Character then check it }
  86.     CH := UpCase(CH);
  87.     EscapePushed := (Ch = Chr(27));
  88.   end
  89.   else
  90.     EscapePushed := False;
  91. end;
  92.  
  93. Procedure ConfirmQuit(Var ESC : Boolean);
  94. { confirms that the user wants to quit printing }
  95. Var
  96.   CH : Char;
  97. begin
  98.   YNWin('Cancel all print jobs? (Y/N)',Ch,Mycolor);
  99.   ESC := (CH = 'Y');
  100. end;
  101.  
  102. Procedure PrintCh(CH : Char; Underline : Boolean; Var OK : Boolean);
  103. { Writes a single Character to the Printer }
  104. begin
  105.   if UnderLine then
  106.     {$I-} Write(LST, #27#45#1, CH, #27#45#0) {$I+}
  107.   else
  108.     {$I-} Write(lst,CH); {$I+}
  109.   OK := (IOResult = 0);
  110. end;
  111.  
  112. Procedure MakeLine(Start, Stop : Integer; Return : Boolean; Var ESC : Boolean);
  113. { Draws a line on the paper starting at Start and ending at Stop. }
  114. Var
  115.   PrnReady,
  116.   Ok       : Boolean;
  117. begin
  118.   PrnReady := True;
  119.   Repeat
  120.     PrnReady := PrinterReady;
  121.     if not PRnReady then
  122.       GetPrnError(ESC);
  123.   Until PrnReady or ESC;
  124.  
  125.   PrnReady := True;
  126.   While prnReady and not Esc and (Start <> Stop + 1) DO
  127.   begin
  128.     prnReady := PrinterReady;  { do three test to be sure }
  129.     if not PRnReady then
  130.       GetPrnError(ESC);
  131.     if not ESC then
  132.       PrintCH('_',False,OK);
  133.     if not ESC then
  134.       if EscapePushed then
  135.         ConfirmQuit(ESC);
  136.     if OK then
  137.       Inc(Start);
  138.   end;
  139.   if not Esc and PrnReady and RETURN then
  140.     {$I-} Writeln(LST); {$I+}
  141. end;
  142.  
  143. Procedure WriteStr(TheStr : String; Return, UnderLine : Boolean;
  144.                    Var ESC : Boolean);
  145. Var
  146.   PrnReady,
  147.   OK       : Boolean;
  148.   I        : Byte;
  149. begin
  150.   Repeat
  151.     PrnReady := PrinterReady;
  152.     if not PRnReady then
  153.       GetPrnError(ESC);
  154.   Until PrnReady or ESC;
  155.   I := 1;
  156.  
  157.   While PrnReady and not Esc and (I <> Length(theStr)+1) DO
  158.   begin
  159.     PrnReady := PrinterReady;
  160.     if not PRnReady then
  161.       GetPrnError(ESC);
  162.     if not ESC then
  163.       PrintCh(theStr[I], UnderLine, OK);
  164.     if not esc then
  165.       if EscapePushed then
  166.         confirmQuit(Esc);
  167.     if OK then
  168.       Inc(I);
  169.   end;
  170.   if PrnReady and Not ESC And RETURN then
  171.     {$I-} Writeln(LST); {$I+}
  172. end;
  173.